{extend name="_container/table"}

{block name="left"}
{if check_access('add')}
<span class="layui-btn iframe" data-href="{:url('add')}" data-title="添加用户" data-width="80%" data-height="80%">添加用户</span>
{/if}
{/block}

{block name="right"}

{/block}

{block name="table_header"}
<tr>
  <th style="width:8%">排序</th>
  <th>id</th>
  <th>用户名</th>
  <th>角色</th>
  <th>上次登录时间</th>
  <th>上次登录ip</th>
  <th>操作</th>
</tr>
{/block}

{block name="table_body"}
<tr {$v.pid!='顶级'?'hidden  ' : '  '}  {if $v.pid!="顶级"}data-pid="{$v->getData('pid')}"{/if}  {if $v.forefathers} &nbsp; forefathers="{$v.forefathers}"{/if}>
<td ><input style="padding-left: {$v.level * 10}px" class="layui-input" onkeyup="RegularNum0(this)" type='text' value="{$v.sort}" name="sort[]" autocomplete="off" ><input type='hidden' value="{$v.id}" name="id[]"></td>

<td>{$v.id}</td>
<td style="text-align: left;" >
  <span class="layui-badge layui-bg-gray" style="margin-right: 10px;"> lv.{$v.level}</span>
  {for start="1" end="$v[level]"}
  <span style="width: 40px;display: inline-block"></span>
  {/for}
  {if $v.sons}
  <span onclick="expand(this, {$v[id]})" style="width: 20px;display: inline-block">
                                <i class="layui-icon layui-icon-add-circle" style="font-size: 16px; color: #1E9FFF;"></i>
                            </span>
  {else/}
  <span style="width: 20px;display: inline-block"> </span>
  {/if}

  {if $v.level == 1}
  <i class="layui-icon {$v.icon}"></i>
  {/if}
  {$v.username}
</td>
  <td>
    {if $v.adminRole->toArray()}
    {foreach $v.adminRole as $role}
      <span class="layui-badge">{$role->name}</span>
    {/foreach}
    {else/}
    <span class="layui-badge layui-bg-blue">超级管理员</span>
    {/if}
  </td>
  <td>{$v.last_login_time}</td>
  <td>{$v.last_login_ip}</td>
  <td>
    {if check_access('update')}
    <span class="layui-btn layui-btn-sm iframe" data-href="{:url('update', ['id'=>$v.id])}" data-title="编辑角色" data-height="80%" data-width="80%" >编辑</span>
    {/if}
    {if check_access('delete')}
    <span class="layui-btn layui-btn-sm layui-btn-danger ajax_del" data-href="{:url('delete', ['id'=>$v.id])}">删除</span>
    {/if}
  </td>
</tr>
{/block}

{block name="table_footer"}
<button class="layui-btn" onclick="$('.layui-form').attr('action','{:url("updateSort")}');$('.layui-form').submit();" type="button">排序</button>

{/block}

{block name="js"}
<script>
  function expand(obj,id){
    let icon = $(obj).find('i');
    if(icon.hasClass('layui-icon-add-circle')){
      icon.removeClass('layui-icon-add-circle');
      icon.addClass('layui-icon-reduce-circle');
      $('tr[data-pid=' + id + ']').show();
    }else{
      icon.removeClass('layui-icon-reduce-circle');
      icon.addClass('layui-icon-add-circle');
      let  forefathers = $('tr[forefathers*=",' + id + ',"]');
      forefathers.find("i.layui-icon-reduce-circle").removeClass('layui-icon-reduce-circle').addClass('layui-icon-add-circle');
      forefathers.hide();
    }

  }
</script>
{/block}

{/extend}
